﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;

namespace Hotel_Project.Tools.MySqlData_Helps
{
    public static class Dao_MySql_Jjh
    {
        //192.168.0.56
        private static string str = "server=192.168.0.56;user=xxxx;database=hotel;port=3306;password=123456";
        //得到连接对象
        public static MySqlConnection Connect_MySql()
        {
            //定义与数据连接的链接
            MySqlConnection con = new MySqlConnection(str);
            con.Open();
            return con;
        }
        //获得这个操作功能对象
        public static MySqlCommand Get_SqlCommand(string sql)
        {
            return new MySqlCommand(sql, Connect_MySql());
        }
        //除查询以外的操作
        public static int Execut(string sql)
        {
           return Get_SqlCommand(sql).ExecuteNonQuery();  //不能执行查询语句
        }
        //查询操作
        public static DataSet Read_Ececut(string sql)
        {
            DataSet set = new DataSet();
            MySqlDataAdapter adapter = new MySqlDataAdapter(sql, Connect_MySql());
            adapter.Fill(set);
            return set;
        }
    }
}
